import execjs
import requests
from urllib.parse import urlencode

from loguru import logger

ctx = execjs.compile(open("a_bogus.js", encoding="utf-8").read())
headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Content-Type": "application/x-www-form-urlencoded",
    "Origin": "https://haohuo.jinritemai.com",
    "Pragma": "no-cache",
    "Referer": "https://haohuo.jinritemai.com/ecommerce/trade/detail/index.html?origin_type=pc_buyin_group&id=3748013845285830684",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
    "sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Chromium\";v=\"142\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\""
}
cookies = {
    "gfkadpd": "1522,33666",
    "s_v_web_id": "verify_mfl0107g_fd7as8Sj_oiBm_4Mos_8w8g_RW6hfZFMVnkK",
    "ttwid": "1%7C7D_beJ-6igK36xppV3g1dH8RuBRowznTC9vFseqxFCc%7C1757933202%7Ce71819023753191145ff3152997ed272fc59024265635685d37ff12ecc8c048a"
}
url = "https://haohuo.jinritemai.com/aweme/v2/shop/promotion/pack/h5/"
params = {
    "is_h5": "1",
    "is_native_h5": "1",
    "origin_type": "pc_buyin_group",
    "verifyFp": "verify_mfl0107g_fd7as8Sj_oiBm_4Mos_8w8g_RW6hfZFMVnkK",
    "msToken": "S55b1dw9URV88xAXSaoVUtuLmmLBJj-u1-ROFh2vyPrN1qodLoVxTbmfx3zeHbmIoxx2U6Og7A9cs-5w5fYuEPjmSAv1oI74ldWr-ddHCyIw4Gkrb1aB5gTR3ZjnhIYkKZlIt-o_aCXmrL7LoiceslLziywbDxV0lp8CLaGBC2Nh",
    "a_bogus": "d7sRkFSwxxWVcplS8OcRe3xUn0LArBuyaPTxRTsneOE5c1lYp4ltgux5JOOz4e56zuBfoHI7fnzeYDxO0Z5OWZ9kLmkDSqk6Ft2IIzvo2qkkP-ig7r8LeGSEwiPY0A4Yu5IIiM4R1s0F2EcWVH90Ap1Hw/vrRbDdBq-tVMYnx9K4UC8jhn2Aa3idFh-3"
}
data = {
    "ui_params": "{\"from_live\":false,\"from_video\":null,\"three_d_log_data\":null,\"follow_status\":null,\"which_account\":null,\"ad_log_extra\":null,\"from_group_id\":null,\"bolt_param\":null,\"transition_tracker_data\":null,\"selected_ids\":null,\"window_reposition\":null,\"is_short_screen\":null,\"full_mode\":true}",
    "use_new_price": "1",
    "is_h5": "1",
    "bff_type": "2",
    "is_in_app": "0",
    "origin_type": "pc_buyin_group",
    "promotion_ids": "3748013845285830684",
    "meta_param": "",
    "source_page": "",
    "request_additions": "",
    "isFromVideo": "false",
    "enable_timing": "true",
    "gtp_generated_product_desc": "eyJ2ZXJzaW9uIjoiVjItREtNUyIsInRva2VuX2JvZHkiOiJNSUlCTUFRUVFTNjBrWlpVYlJUR0Fxd0pMdHB4M2dTQ0FSZzBRTmlDZ3hrYkZKRG40dUNxNU1ocU9FcHIwQ2xXdWkwMENQS0E4SF9FSFNjX2ZDLVpBcjVYT3VYQllLeERHT2xhbi15NFFkSDdqa25reWN2RVo0Ry1ySExtUmx4dlRBMjVFOWFwM1lodjkzeEVnS0Q2YVJ5NVJkVnRUdDRYYzlsbVBTcEdkeEMzRzdTQWk0MkFObXNsYWFIbzR1aUFLMzM1VG8zaXhMd2pPUXlEc09OV05lRXBuOUk1VmI3SkVRREVueEU2aDRCbGZfdnhuM1dZX1JqLUNvVkFsTmJEV0V0UFdkMGJ2dUw4bGsySnFEa3c4SVhQV0kxWGNzeGRlWFQ5TWExVFN0c0VUSDltdGlZTjN4Slo2UDdwRmZUMlFPMWpWbVM3djRtOEdfZXVUcmJSYVFzZ0QxNUZNLXhobTFZZVMwVHZEUF9lR0VtdEYtZnl2ZEsxMC10dnFfclVncTZxa0EwektnRzIyLXRmS0ZpWFJDVnhCQUEifQ",
    "is_new_h5_bff": "1"
}
query = urlencode(params)
body =urlencode(data)
user_agent = headers["User-Agent"]
a_bogus = ctx.call('encryptAbogus', *(
    user_agent,
        query,
        body
    ))

logger.info(f'a_bogus: {a_bogus}')
response = requests.post(url, headers=headers, cookies=cookies, params=params, data=body)

print(response.text)
print(response)